﻿namespace TanzimSaqib.NoBrainer
{
    using Microsoft.Practices.EnterpriseLibrary.Caching;

    /// <summary>
    /// A caching implementation, uses Caching Application Block as the internal
    /// caching engine
    /// </summary>
    public class EntLibCache : ICacheProvider
    {
        private static ICacheManager _CacheManager;

        public EntLibCache(string cacheManagerName)
        {
            _CacheManager = CacheFactory.GetCacheManager(cacheManagerName);
        }

        public object Get(string key)
        {
            return _CacheManager.GetData(key);
        }

        public void Set(string key, object value)
        {
            if (_CacheManager.Contains(key))
                _CacheManager.Remove(key);

            this.Add(key, value);
        }

        public void Add(string key, object value)
        {
            _CacheManager.Add(key, value);
        }

        public bool Contains(string key)
        {
            return _CacheManager.Contains(key);
        }

        public void Flush()
        {
            _CacheManager.Flush();
        }

        public void Remove(string key)
        {
            _CacheManager.Remove(key);
        }
    }
}
